Release 10.1A: OpenEdge Development:
Progress 4GL Handbook
Using built-In 4GL functions
To complete this latest change to the procedure, you need to define the statement that checks whether the ShipDate is Unknown, and then picks out the month from the date, using the cMonthList variable you defined just above, and converts it to one of the three-letter abbreviations in the list. Here is the whole statement:
Now take a closer look at the elements in the
DISPLAYstatement. First there is a new keyword,ENTRY. This is the name of a built-in function in the 4GL. There are many such functions to do useful jobs for you, to save you the work of writing the code to do it yourself. TheENTRYfunction takes two arguments, and as you can see, those arguments are enclosed in parentheses. The first is anINTEGERvalue, which identifies an entry in a comma-separated list of character values. In this case it represents the month of the year, from 1 to 12. The second argument is the list that contains the entry the function is retrieving. In this case it is the variable you just defined.Looking closer, you can see that the first of the two arguments to the function,
MONTH(ShipDate),is itself another function. This function takes a ProgressDATEvalue as an argument, extracts the month number of the date, and returns it. The returned value is anINTEGERfrom 1 to 12 that theENTRYfunction then uses to pick out the right entry from the list of months in cMonthList. So if the month is May, theMONTHfunction returns 5 and theENTRYfunction picks out the fifth entry from the list of months and returns it to theDISPLAYstatement.Here are some general observations about built-in functions:
- A function takes a variable number of arguments, depending on what the function requires. Some functions take no arguments at all (for example, the
TODAYfunction, which returns today’s date). Some functions have a variable number of arguments, so that one or more arguments at the end of the argument list are optional. For example, theENTRYfunction can have an optional third argument, which is a character string representing a delimiter to use between the values in the list, if you don’t want it to use a comma (,). Because the comma is the default delimiter, it is optional. You can’t leave out arguments from the middle of the list, or specify them in a different order. Each of the arguments must be of the proper data type, depending on what the function expects.- The arguments to a function can be constant values, variable names, database field names, or any expression involving these which evaluates to a value of the proper data type.
- Each function returns a value of a specific data type.
- You can nest functions to any depth in your code. The result of any function is returned up to the next level in the code.
- You can place functions anywhere within a statement where a value can appear. Because a function returns a value, it can appear only on the right-side of an assignment statement. You can’t use the
MONTHfunction to assign the month value to a date variable, for example, or theENTRYfunction to assign the value of an entry in a list. There are 4GL statement keywords in some cases to do those kinds of assignments.- If you are displaying the result of a function or an expression involving a function, you can specify a
LABELorFORMATfor it, just as you can for a variable. The defaultLABELfor an expression is a text string representing the expression itself. The default format is the default for the function’s data type. In this example you should add the label Month to the expression.
![]()
To display the month along with each Order:
- Add the new statement with the function references into your procedure, inside the block of code that loops through the Orders:
- To see the effect of the new code, rerun the procedure:
Note: Several separate 4GL
![]()
DISPLAYstatements contribute to the display of fields in a single line for each Order. This is one of the powerful and flexible characteristics of the 4GL. Progress can gather together a number of different statements in a procedure, some of which might be executed conditionally, and combine them together into a single operation such as this. This feature is generally not possible with other programming languages.- To save your procedure, press F6.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |